<?php namespace Common\Model;
use Hdphp\Model\Model;
class Type extends Model{
	protected $table = 'type';
	//自动验证
	protected $validate = array(
		array('tname','required','类型名称不能为空',3,3)
	);
	public function store(){
		if($this->create()){
			//添加
			$this->add();
			return TRUE;				
		}else{		
			return FALSE;	
		}
	    
	}
	//获取全部数据
	public function getType(){
		//获取所有数据
		$type = $this->count();
		//分页
	    $page = Page::row(6)->make($type);
		//
		$typeData = $this->limit(Page::limit())->get();	
		$data = array(
			'page' => $page,
			'data' => $typeData 
		);
		return $data;
	}
	//修改
	public function edit($tid){
		//触发自动验证
	    if(!$this->create()){
	    		 return FALSE;
	    }else{
	    	//修改type表
		$this->save();
	    	return TRUE;
	    }	
	}
	//删除
	public function del($tid){
		$typeAttrModel = new \Common\Model\TypeAttr;
		$typeAttrData = $typeAttrModel->where("ygshop_type_tid={$tid}")->find();
		if($typeAttrData){
			$this->error = '请先删除该类型下的属性';
			return FALSE;
		}
		$this->where(array('tid'=>$tid))->delete();
		return TRUE;
	}
}













 ?>